#pragma once
#include "stdafx.h"

// Defines
#define __LONGSTRING(string) L##string
#define LONGSTRING(string) __LONGSTRING(string)

// Goes to CLEANUP on Failure_
#define CHECK_HR(hr)      \
   if(FAILED(hr))         \
      goto CLEANUP

// Goes to CLEANUP on Failure, and displays any ErrorInfo
/*#define XCHECK_HR(hr) { \
   if( g_dwFlags & DISPLAY_METHODCALLS )                            \
      _ftprintf_s(stderr, LONGSTRING(#hr) _TEXT("\n"));                      \
   if(FAILED(myHandleResult(hr, LONGSTRING(__FILE__), __LINE__)))   \
      goto CLEANUP;                                                 \
}*/

#define CHECK_MEMORY(hr, pv)   \
{                              \
   if(!pv)                     \
   {                           \
      hr = E_OUTOFMEMORY;      \
      CHECK_HR(hr);            \
   }                           \
}

// ROUNDUP on all platforms pointers must be aligned properly
#define ROUNDUP_AMOUNT            8
#define ROUNDUP_(size,amount) (((ULONG)(size)+((amount)-1))&~((amount)-1))
#define ROUNDUP(size)             ROUNDUP_(size, ROUNDUP_AMOUNT)

const TCHAR SQL_DROP_WUBI_CODE_TABLE[]			= _TEXT("DROP TABLE %s");
const TCHAR SQL_CREATE_WUBI_SYS_CODE_TABLE[]	=
	_TEXT("CREATE TABLE [%s] (CodeId INT IDENTITY NOT NULL PRIMARY KEY, [WubiCode] nvarchar(20) NOT NULL, ") \
	_TEXT("PinYinCode nvarchar(20), GBChars nvarchar(40) NOT NULL, [DisplayOrder] integer NOT NULL, IsSystemCode bit NOT NULL)");

const TCHAR CODE_TABLE[]=_TEXT("Code");
//const TCHAR USER_CODE[]=_TEXT("UserCode");
const TCHAR CODE_INDEX[]=_TEXT("PK_Code");

const TCHAR SQL_CREATE_WUBICODE_INDEX[]	= _TEXT("CREATE INDEX %s on WubiCode (CodeId ASC)");

const TCHAR SQL_INSERT_WUBI_CODE[]=
	_TEXT("Insert into [%s]([WubiCode], PinYinCode, GBChars, [DisplayOrder], IsSystemCode) values(?, ?, ?, ?, ?)");
